package com.nf.health.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.SchemeCaterogyList;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class SchemeCategoryAdapter extends BaseAdapter {
	private Context context;
	private List<SchemeCaterogyList> listHealthy;
	private String type;

	public SchemeCategoryAdapter(Context context, List<SchemeCaterogyList> listHealthy) {
		this.context = context;
		this.listHealthy = listHealthy;
	}

	@Override
	public int getCount() {
		return listHealthy.size();
	}

	@Override
	public Object getItem(int position) {
		return listHealthy.get(position);
	}

	@Override
	public long getItemId(int id) {
		return id;
	}

	@Override
	public View getView(final int position, View view, ViewGroup viewGroup) {
		ViewHolder holder;
		if (view == null) {
			view = View
					.inflate(context, R.layout.item_healthy_plan, null);
			holder = new ViewHolder();
			holder.sport_icon = (ImageView) view.findViewById(R.id.sport_icon);
			holder.sport_name = (TextView) view.findViewById(R.id.sport_name);
			holder.hold_finish = (ImageView) view.findViewById(R.id.hold_finish);
			holder.sport_type = (TextView) view
					.findViewById(R.id.sport_suit_type);
			view.setTag(holder);

		} else {
			holder = (ViewHolder) view.getTag();
		}

		ImageLoaderUtils.getinstance(context).getImage(
				holder.sport_icon,
				listHealthy.get(position).getHimg(),
				R.drawable.new_default_nf_icon);
		holder.sport_name.setText(listHealthy.get(position).getDetail()
				.toString());

		holder.sport_type.setText(listHealthy.get(position).getDescribe().toString());

		holder.hold_finish
				.setBackgroundResource(R.drawable.home_add_hplan);
		holder.hold_finish.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View view) {
				listener.onClick(position, "");
			}
		});
		return view;
	}

	class ViewHolder {
		ImageView sport_icon;
		TextView sport_name, sport_type;
		ImageView hold_finish;

	}
	private OnMyClickListener listener;
	public void setOnMyClickListener(OnMyClickListener listener) {
		this.listener = listener;
	}
}
